package main

import (
	"fmt"
	"os"
)

type User struct {
	UserName string
	UserId int
	Gender int
}

type List []*User


func main() {
	var List List

	for {
		var op int
		List.queryAll()
		fmt.Printf("欢迎来到人员管理系统,当前用户有:%d人。", len(List))
		fmt.Println(" 1-添加人员 2-查看人员 3-删除人员 4-退出系统")
		fmt.Scan(&op)
		switch op {
		case 1:
			var user User
			fmt.Println("请依次输入人员姓名 ID 性别 1-男,2-女")
			fmt.Scan(&user.UserName, &user.UserId, &user.Gender)
			List.add(&user)
		case 2:
			List.queryAll()
		case 3:
			var id uint
			fmt.Println("请输入人员Id")
			fmt.Scan(&id)
			List.del(&id)
		case 4:
			os.Exit(0)
		default:
			fmt.Println("操作指令异常")
		}
		fmt.Println("----------------------------------------------------------------\n")
	}

}

func (list *List)add(user *User) {
	for _, v := range *list{
		if (v.UserId == user.UserId) {
			fmt.Println("您添加的ID已存在")
		} else {
			*list = append(*list, user)
		}
	}
}

func (list *List)queryAll() {

	for k, v := range *list {
		fmt.Printf("NO.%d 姓名:%s,Id:%d,性别%d\n", k+1, (*v).UserName, (*v).UserId, (*v).Gender)
	}
	fmt.Println("********************************************************************")
}

func (list *List)del(index *uint) {
	var pos int
	pos = int(*index)
	if len(*list)+1 > pos {
		fmt.Println("删除的数据不存在")
	} else {
		for k, _ := range *list {
			if k == pos {
				*list = append((*list)[:k], (*list)[k+1:]...)
				fmt.Println("删除成功")
			} else {
				fmt.Println("删除的数据不存在")
			}
		}
	}
}
